package org.example.demo2;

import lombok.extern.slf4j.Slf4j;

import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author Gong.Yang
 */
@Slf4j
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Runnable task = () -> {
            String id = UUID.randomUUID().toString();
            log.info("a before id->{}", id);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("a after id->{}", id);
        };
        ExecutorService pool = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 10; i++) {
            pool.execute(task);
        }
        Thread.sleep(2000);
//        pool.shutdown();//拒绝任务入队，但是会将当前任务完成
        pool.shutdownNow(); //直接关闭，杀死正在运行的线程
    }
}
